#include <iostream>
using namespace std;

/*
    1.cout是ostream类的对象
        cout对象重载了<<运算符（插入运算符 << ）
    原型是ostream &operator<<(参数列表)
    int n1 = 78 ;cout << n1 ;调用的是 ostream& operator<<(int val)
    2.调用对象是cout    ostream类对象
        因此重载<<  只能作为友元函数，不能是成员函数

*/

class Cat
{
public:
    Cat(string _name, int _age)
    {
        name = _name;
        age = _age;
    }
    Cat() {}
    void show()
    {
        cout << "name:" << name << " age:" << age << endl;
    }
    friend ostream &operator<<(ostream &out, Cat &cat);

private:
    string name;
    int age;
};

ostream &operator<<(ostream &cout, Cat &cat)
{
    cout << "姓名:" << cat.name << " 年龄:" << cat.age << endl;
    return cout;
}



int main()
{
    Cat c1("汤姆", 13);
    Cat c2("杰瑞", 15);
    cout << c1 << c2;

    operator<<(cout, c1);
    return 0;
}